package com.selen.controller;

import com.selen.dto.PageDTO;
import com.selen.dto.RoleInsertDTO;
import com.selen.dto.RoleUpdateDTO;
import com.selen.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "角色模块")
@RestController
@RequestMapping("/api/v1/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Operation(summary = "添加一条记录")
    @PostMapping("/save")
    public Object save(@RequestBody @Validated RoleInsertDTO dto) {
        return roleService.insert(dto);
    }

    @Operation(summary = "查询一条记录")
    @GetMapping("/getInfo/{id}")
    public Object getInfo(@PathVariable Long id) {
        return roleService.selectById(id);
    }

    @Operation(summary = "修改一条记录")
    @PostMapping("/update")
    public Object update(@RequestBody @Validated RoleUpdateDTO dto) {
        return roleService.updateById(dto);
    }

    @Operation(summary = "删除一条记录")
    @PostMapping("/remove/{id}")
    public Object remove(@PathVariable Long id) {
        return roleService.logicDeleteById(id);
    }

    @Operation(summary = "批量删除记录")
    @PostMapping("/removeBatch")
    public Object removeBatch(@RequestParam List<Long> ids) {
        return roleService.logicDeleteByIds(ids);
    }

    @Operation(summary = "查询全部记录")
    @GetMapping("/list")
    public Object list() {
        return roleService.list();
    }

    @Operation(summary = "分页查询记录")
    @PostMapping("/page")
    public Object page(@RequestBody @Validated PageDTO dto) {
        return roleService.page(dto);
    }

}
